package cn.lupin.utils;

import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.rabbit.core.RabbitTemplate;

import java.nio.charset.StandardCharsets;

public class RabbitMqSender {

    private static final String DEFAULT_EXCHANGE = "laugh-videos-exchange";

    private static final String DEFAULT_ROUTING_KEY = "bgm-upload";

    private RabbitTemplate rabbitTemplate;

    public RabbitMqSender() {
    }

    public RabbitMqSender(RabbitTemplate rabbitTemplate) {
        this.rabbitTemplate = rabbitTemplate;
    }

    public void sendMessage(String data) {
        Message message = new Message(data.getBytes(StandardCharsets.UTF_8),new MessageProperties());
        rabbitTemplate.convertAndSend(DEFAULT_EXCHANGE, DEFAULT_ROUTING_KEY, message);
    }

    public void sendMessage(Object data) {
        rabbitTemplate.convertAndSend(DEFAULT_EXCHANGE, DEFAULT_ROUTING_KEY, data);
    }
}
